
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_Hans">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Django 2.1 版本发行说明 &#8212; Django 3.2.11.dev 文档</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="Django 2.0.13 版本发行说明" href="2.0.13.html" />
    <link rel="prev" title="Django 2.1.1 版本发行说明" href="2.1.1.html" />



 
<script src="../templatebuiltins.js"></script>
<script>
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);</script>

  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../index.html">Django 3.2.11.dev 文档</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../index.html">Home</a>  |
        <a title="Table of contents" href="../contents.html">Table of contents</a>  |
        <a title="Global index" href="../genindex.html">Index</a>  |
        <a title="Module index" href="../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="2.1.1.html" title="Django 2.1.1 版本发行说明">previous</a>
     |
    <a href="index.html" title="发行说明" accesskey="U">up</a>
   |
    <a href="2.0.13.html" title="Django 2.0.13 版本发行说明">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="releases-2.1">
            
  <div class="section" id="s-django-2-1-release-notes">
<span id="django-2-1-release-notes"></span><h1>Django 2.1 版本发行说明<a class="headerlink" href="#django-2-1-release-notes" title="永久链接至标题">¶</a></h1>
<p><em>2018 年 8 月 1 日</em></p>
<p>Welcome to Django 2.1!</p>
<p>These release notes cover the <a class="reference internal" href="#whats-new-2-1"><span class="std std-ref">new features</span></a>, as well as
some <a class="reference internal" href="#backwards-incompatible-2-1"><span class="std std-ref">backwards incompatible changes</span></a> you'll
want to be aware of when upgrading from Django 2.0 or earlier. We've
<a class="reference internal" href="#removed-features-2-1"><span class="std std-ref">dropped some features</span></a> that have reached the end of
their deprecation cycle, and we've <a class="reference internal" href="#deprecated-features-2-1"><span class="std std-ref">begun the deprecation process for some
features</span></a>.</p>
<p>如果你要更新现有的项目，请看 <a class="reference internal" href="../howto/upgrade-version.html"><span class="doc">升级 Django 到最新的版本</span></a> 指南。</p>
<div class="section" id="s-python-compatibility">
<span id="python-compatibility"></span><h2>Python 兼容性<a class="headerlink" href="#python-compatibility" title="永久链接至标题">¶</a></h2>
<p>Django 2.1 supports Python 3.5, 3.6, and 3.7. Django 2.0 is the last version to
support Python 3.4.  We <strong>highly recommend</strong> and only officially support the
latest release of each series.</p>
</div>
<div class="section" id="s-what-s-new-in-django-2-1">
<span id="s-whats-new-2-1"></span><span id="what-s-new-in-django-2-1"></span><span id="whats-new-2-1"></span><h2>What's new in Django 2.1<a class="headerlink" href="#what-s-new-in-django-2-1" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-model-view-permission">
<span id="model-view-permission"></span><h3>Model &quot;view&quot; permission<a class="headerlink" href="#model-view-permission" title="永久链接至标题">¶</a></h3>
<p>A &quot;view&quot; permission is added to the model <a class="reference internal" href="../ref/models/options.html#django.db.models.Options.default_permissions" title="django.db.models.Options.default_permissions"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Meta.default_permissions</span></code></a>. The new permissions will be
created automatically when running <a class="reference internal" href="../ref/django-admin.html#django-admin-migrate"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">migrate</span></code></a>.</p>
<p>This allows giving users read-only access to models in the admin.
<a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.has_view_permission" title="django.contrib.admin.ModelAdmin.has_view_permission"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ModelAdmin.has_view_permission()</span></code></a> is new. The implementation is backwards
compatible in that there isn't a need to assign the &quot;view&quot; permission to allow
users who have the &quot;change&quot; permission to edit objects.</p>
<p>There are a couple of <a class="reference internal" href="#view-permission-backwards-incompatible"><span class="std std-ref">backwards incompatible considerations</span></a>.</p>
</div>
<div class="section" id="s-minor-features">
<span id="minor-features"></span><h3>次要特性<a class="headerlink" href="#minor-features" title="永久链接至标题">¶</a></h3>
<div class="section" id="s-django-contrib-admin">
<span id="django-contrib-admin"></span><h4><a class="reference internal" href="../ref/contrib/admin/index.html#module-django.contrib.admin" title="django.contrib.admin: Django's admin site."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.admin</span></code></a><a class="headerlink" href="#django-contrib-admin" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.search_fields" title="django.contrib.admin.ModelAdmin.search_fields"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ModelAdmin.search_fields</span></code></a> now accepts any lookup such as
<code class="docutils literal notranslate"><span class="pre">field__exact</span></code>.</li>
<li>jQuery is upgraded from version 2.2.3 to 3.3.1.</li>
<li>The new <a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.delete_queryset" title="django.contrib.admin.ModelAdmin.delete_queryset"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ModelAdmin.delete_queryset()</span></code></a> method allows customizing the
deletion process of the &quot;delete selected objects&quot; action.</li>
<li>You can now <a class="reference internal" href="../ref/contrib/admin/index.html#overriding-default-admin-site"><span class="std std-ref">override the default admin site</span></a>.</li>
<li>The new <a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.sortable_by" title="django.contrib.admin.ModelAdmin.sortable_by"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ModelAdmin.sortable_by</span></code></a> attribute and
<a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.get_sortable_by" title="django.contrib.admin.ModelAdmin.get_sortable_by"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ModelAdmin.get_sortable_by()</span></code></a> method allow limiting the columns that
can be sorted in the change list page.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">admin_order_field</span></code> attribute for elements in
<a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.list_display" title="django.contrib.admin.ModelAdmin.list_display"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ModelAdmin.list_display</span></code></a> may now be a query expression.</li>
<li>The new <a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.get_deleted_objects" title="django.contrib.admin.ModelAdmin.get_deleted_objects"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ModelAdmin.get_deleted_objects()</span></code></a> method allows customizing
the deletion process of the delete view and the &quot;delete selected&quot; action.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">actions.html</span></code>, <code class="docutils literal notranslate"><span class="pre">change_list_results.html</span></code>, <code class="docutils literal notranslate"><span class="pre">date_hierarchy.html</span></code>,
<code class="docutils literal notranslate"><span class="pre">pagination.html</span></code>, <code class="docutils literal notranslate"><span class="pre">prepopulated_fields_js.html</span></code>, <code class="docutils literal notranslate"><span class="pre">search_form.html</span></code>,
and <code class="docutils literal notranslate"><span class="pre">submit_line.html</span></code> templates can now be <a class="reference internal" href="../ref/contrib/admin/index.html#admin-templates-overridden-per-app-or-model"><span class="std std-ref">overridden per app or
per model</span></a> (besides overridden
globally).</li>
<li>The admin change list and change form object tools can now be <a class="reference internal" href="../ref/contrib/admin/index.html#admin-templates-overridden-per-app-or-model"><span class="std std-ref">overridden
per app, per model, or globally</span></a>
with <code class="docutils literal notranslate"><span class="pre">change_list_object_tools.html</span></code> and
<code class="docutils literal notranslate"><span class="pre">change_form_object_tools.html</span></code> templates.</li>
<li><a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.InlineModelAdmin.has_add_permission" title="django.contrib.admin.InlineModelAdmin.has_add_permission"><code class="xref py py-meth docutils literal notranslate"><span class="pre">InlineModelAdmin.has_add_permission()</span></code></a> is now passed the parent object
as the second positional argument, <code class="docutils literal notranslate"><span class="pre">obj</span></code>.</li>
<li>Admin actions may now <a class="reference internal" href="../ref/contrib/admin/actions.html#admin-action-permissions"><span class="std std-ref">specify permissions</span></a>
to limit their availability to certain users.</li>
</ul>
</div>
<div class="section" id="s-django-contrib-auth">
<span id="django-contrib-auth"></span><h4><a class="reference internal" href="../topics/auth/index.html#module-django.contrib.auth" title="django.contrib.auth: Django's authentication framework."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.auth</span></code></a><a class="headerlink" href="#django-contrib-auth" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li><a class="reference internal" href="../ref/django-admin.html#django-admin-createsuperuser"><code class="xref std std-djadmin docutils literal notranslate"><span class="pre">createsuperuser</span></code></a> now gives a prompt to allow bypassing the
<a class="reference internal" href="../ref/settings.html#std:setting-AUTH_PASSWORD_VALIDATORS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">AUTH_PASSWORD_VALIDATORS</span></code></a> checks.</li>
</ul>
</div>
<div class="section" id="s-django-contrib-gis">
<span id="django-contrib-gis"></span><h4><a class="reference internal" href="../ref/contrib/gis/index.html#module-django.contrib.gis" title="django.contrib.gis: Geographic Information System (GIS) extensions for Django"><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.gis</span></code></a><a class="headerlink" href="#django-contrib-gis" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The new <a class="reference internal" href="../ref/contrib/gis/geos.html#django.contrib.gis.geos.GEOSGeometry.buffer_with_style" title="django.contrib.gis.geos.GEOSGeometry.buffer_with_style"><code class="xref py py-meth docutils literal notranslate"><span class="pre">GEOSGeometry.buffer_with_style()</span></code></a> method is a version of
<a class="reference internal" href="../ref/contrib/gis/geos.html#django.contrib.gis.geos.GEOSGeometry.buffer" title="django.contrib.gis.geos.GEOSGeometry.buffer"><code class="xref py py-meth docutils literal notranslate"><span class="pre">buffer()</span></code></a> that allows customizing the style of the
buffer.</li>
<li><a class="reference internal" href="../ref/contrib/gis/forms-api.html#django.contrib.gis.forms.widgets.OpenLayersWidget" title="django.contrib.gis.forms.widgets.OpenLayersWidget"><code class="xref py py-class docutils literal notranslate"><span class="pre">OpenLayersWidget</span></code></a> is now based on
OpenLayers 4.6.5 (previously 3.20.1).</li>
</ul>
</div>
<div class="section" id="s-django-contrib-sessions">
<span id="django-contrib-sessions"></span><h4><a class="reference internal" href="../topics/http/sessions.html#module-django.contrib.sessions" title="django.contrib.sessions: Provides session management for Django projects."><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.sessions</span></code></a><a class="headerlink" href="#django-contrib-sessions" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>Added the <a class="reference internal" href="../ref/settings.html#std:setting-SESSION_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SESSION_COOKIE_SAMESITE</span></code></a> setting to set the <code class="docutils literal notranslate"><span class="pre">SameSite</span></code>
cookie flag on session cookies.</li>
</ul>
</div>
<div class="section" id="s-cache">
<span id="cache"></span><h4>缓存<a class="headerlink" href="#cache" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The <a class="reference internal" href="../topics/cache.html#local-memory-caching"><span class="std std-ref">local-memory cache backend</span></a> now uses a
least-recently-used (LRU) culling strategy rather than a pseudo-random one.</li>
<li>The new <a class="reference internal" href="../topics/cache.html#django.core.caches.cache.touch" title="django.core.caches.cache.touch"><code class="xref py py-meth docutils literal notranslate"><span class="pre">touch()</span></code></a> method of the <a class="reference internal" href="../topics/cache.html#low-level-cache-api"><span class="std std-ref">low-level
cache API</span></a> updates the timeout of cache keys.</li>
</ul>
</div>
<div class="section" id="s-csrf">
<span id="csrf"></span><h4>CSRF<a class="headerlink" href="#csrf" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>Added the <a class="reference internal" href="../ref/settings.html#std:setting-CSRF_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CSRF_COOKIE_SAMESITE</span></code></a> setting to set the <code class="docutils literal notranslate"><span class="pre">SameSite</span></code>
cookie flag on CSRF cookies.</li>
</ul>
</div>
<div class="section" id="s-forms">
<span id="forms"></span><h4>表单<a class="headerlink" href="#forms" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The widget for <code class="docutils literal notranslate"><span class="pre">ImageField</span></code> now renders with the HTML attribute
<code class="docutils literal notranslate"><span class="pre">accept=&quot;image/*&quot;</span></code>.</li>
</ul>
</div>
<div class="section" id="s-internationalization">
<span id="internationalization"></span><h4>国际化<a class="headerlink" href="#internationalization" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>Added the <a class="reference internal" href="../ref/utils.html#django.utils.translation.get_supported_language_variant" title="django.utils.translation.get_supported_language_variant"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_supported_language_variant()</span></code></a>
function.</li>
<li>Untranslated strings for territorial language variants now use the
translations of the generic language. For example, untranslated <code class="docutils literal notranslate"><span class="pre">pt_BR</span></code>
strings use <code class="docutils literal notranslate"><span class="pre">pt</span></code> translations.</li>
</ul>
</div>
<div class="section" id="s-management-commands">
<span id="management-commands"></span><h4>管理命令<a class="headerlink" href="#management-commands" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The new <a class="reference internal" href="../ref/django-admin.html#cmdoption-inspectdb-include-views"><code class="xref std std-option docutils literal notranslate"><span class="pre">inspectdb</span> <span class="pre">--include-views</span></code></a> option allows creating models
for database views.</li>
<li>The <a class="reference internal" href="../howto/custom-management-commands.html#django.core.management.BaseCommand" title="django.core.management.BaseCommand"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseCommand</span></code></a> class now uses a custom help
formatter so that the standard options like <code class="docutils literal notranslate"><span class="pre">--verbosity</span></code> or <code class="docutils literal notranslate"><span class="pre">--settings</span></code>
appear last in the help output, giving a more prominent position to subclassed
command's options.</li>
</ul>
</div>
<div class="section" id="s-migrations">
<span id="migrations"></span><h4>迁移<a class="headerlink" href="#migrations" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>Added support for serialization of <code class="docutils literal notranslate"><span class="pre">functools.partialmethod</span></code> objects.</li>
<li>To support frozen environments, migrations may be loaded from <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files.</li>
</ul>
</div>
<div class="section" id="s-models">
<span id="models"></span><h4>模型<a class="headerlink" href="#models" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>Models can now use <code class="docutils literal notranslate"><span class="pre">__init_subclass__()</span></code> from <span class="target" id="index-0"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0487"><strong>PEP 487</strong></a>.</li>
<li>A <code class="docutils literal notranslate"><span class="pre">BinaryField</span></code> may now be set to <code class="docutils literal notranslate"><span class="pre">editable=True</span></code> if you wish to include
it in model forms.</li>
<li>A number of new text database functions are added:
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.Chr" title="django.db.models.functions.Chr"><code class="xref py py-class docutils literal notranslate"><span class="pre">Chr</span></code></a>,
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.Left" title="django.db.models.functions.Left"><code class="xref py py-class docutils literal notranslate"><span class="pre">Left</span></code></a>,
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.LPad" title="django.db.models.functions.LPad"><code class="xref py py-class docutils literal notranslate"><span class="pre">LPad</span></code></a>,
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.LTrim" title="django.db.models.functions.LTrim"><code class="xref py py-class docutils literal notranslate"><span class="pre">LTrim</span></code></a>,
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.Ord" title="django.db.models.functions.Ord"><code class="xref py py-class docutils literal notranslate"><span class="pre">Ord</span></code></a>,
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.Repeat" title="django.db.models.functions.Repeat"><code class="xref py py-class docutils literal notranslate"><span class="pre">Repeat</span></code></a>,
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.Replace" title="django.db.models.functions.Replace"><code class="xref py py-class docutils literal notranslate"><span class="pre">Replace</span></code></a>,
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.Right" title="django.db.models.functions.Right"><code class="xref py py-class docutils literal notranslate"><span class="pre">Right</span></code></a>,
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.RPad" title="django.db.models.functions.RPad"><code class="xref py py-class docutils literal notranslate"><span class="pre">RPad</span></code></a>,
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.RTrim" title="django.db.models.functions.RTrim"><code class="xref py py-class docutils literal notranslate"><span class="pre">RTrim</span></code></a>, and
<a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.Trim" title="django.db.models.functions.Trim"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trim</span></code></a>.</li>
<li>The new <a class="reference internal" href="../ref/models/database-functions.html#django.db.models.functions.TruncWeek" title="django.db.models.functions.TruncWeek"><code class="xref py py-class docutils literal notranslate"><span class="pre">TruncWeek</span></code></a> function truncates
<a class="reference internal" href="../ref/models/fields.html#django.db.models.DateField" title="django.db.models.DateField"><code class="xref py py-class docutils literal notranslate"><span class="pre">DateField</span></code></a> and
<a class="reference internal" href="../ref/models/fields.html#django.db.models.DateTimeField" title="django.db.models.DateTimeField"><code class="xref py py-class docutils literal notranslate"><span class="pre">DateTimeField</span></code></a> to the Monday of a week.</li>
<li>Query expressions can now be negated using a minus sign.</li>
<li><a class="reference internal" href="../ref/models/querysets.html#django.db.models.query.QuerySet.order_by" title="django.db.models.query.QuerySet.order_by"><code class="xref py py-meth docutils literal notranslate"><span class="pre">QuerySet.order_by()</span></code></a> and <a class="reference internal" href="../ref/models/querysets.html#django.db.models.query.QuerySet.distinct" title="django.db.models.query.QuerySet.distinct"><code class="xref py py-meth docutils literal notranslate"><span class="pre">distinct(*fields)</span></code></a>
now support using field transforms.</li>
<li><a class="reference internal" href="../ref/models/fields.html#django.db.models.BooleanField" title="django.db.models.BooleanField"><code class="xref py py-class docutils literal notranslate"><span class="pre">BooleanField</span></code></a> can now be <code class="docutils literal notranslate"><span class="pre">null=True</span></code>. This is
encouraged instead of <a class="reference internal" href="../ref/models/fields.html#django.db.models.NullBooleanField" title="django.db.models.NullBooleanField"><code class="xref py py-class docutils literal notranslate"><span class="pre">NullBooleanField</span></code></a>, which will
likely be deprecated in the future.</li>
<li>The new <a class="reference internal" href="../ref/models/querysets.html#django.db.models.query.QuerySet.explain" title="django.db.models.query.QuerySet.explain"><code class="xref py py-meth docutils literal notranslate"><span class="pre">QuerySet.explain()</span></code></a> method displays the database's execution
plan of a queryset's query.</li>
<li><a class="reference internal" href="../ref/models/querysets.html#django.db.models.query.QuerySet.raw" title="django.db.models.query.QuerySet.raw"><code class="xref py py-meth docutils literal notranslate"><span class="pre">QuerySet.raw()</span></code></a> now supports <a class="reference internal" href="../ref/models/querysets.html#django.db.models.query.QuerySet.prefetch_related" title="django.db.models.query.QuerySet.prefetch_related"><code class="xref py py-meth docutils literal notranslate"><span class="pre">prefetch_related()</span></code></a>.</li>
</ul>
</div>
<div class="section" id="s-requests-and-responses">
<span id="requests-and-responses"></span><h4>请求和响应<a class="headerlink" href="#requests-and-responses" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>Added <a class="reference internal" href="../ref/request-response.html#django.http.HttpRequest.get_full_path_info" title="django.http.HttpRequest.get_full_path_info"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HttpRequest.get_full_path_info()</span></code></a>.</li>
<li>Added the <code class="docutils literal notranslate"><span class="pre">samesite</span></code> argument to <a class="reference internal" href="../ref/request-response.html#django.http.HttpResponse.set_cookie" title="django.http.HttpResponse.set_cookie"><code class="xref py py-meth docutils literal notranslate"><span class="pre">HttpResponse.set_cookie()</span></code></a> to allow
setting the <code class="docutils literal notranslate"><span class="pre">SameSite</span></code> cookie flag.</li>
<li>The new <code class="docutils literal notranslate"><span class="pre">as_attachment</span></code> argument for <a class="reference internal" href="../ref/request-response.html#django.http.FileResponse" title="django.http.FileResponse"><code class="xref py py-class docutils literal notranslate"><span class="pre">FileResponse</span></code></a>
sets the <code class="docutils literal notranslate"><span class="pre">Content-Disposition</span></code> header to make the browser ask if the user
wants to download the file. <code class="docutils literal notranslate"><span class="pre">FileResponse</span></code> also tries to set the
<code class="docutils literal notranslate"><span class="pre">Content-Type</span></code> and <code class="docutils literal notranslate"><span class="pre">Content-Length</span></code> headers where appropriate.</li>
</ul>
</div>
<div class="section" id="s-templates">
<span id="templates"></span><h4>模板<a class="headerlink" href="#templates" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>The new <a class="reference internal" href="../ref/templates/builtins.html#std:templatefilter-json_script"><code class="xref std std-tfilter docutils literal notranslate"><span class="pre">json_script</span></code></a> filter safely outputs a Python object as JSON,
wrapped in a <code class="docutils literal notranslate"><span class="pre">&lt;script&gt;</span></code> tag, ready for use with JavaScript.</li>
</ul>
</div>
<div class="section" id="s-tests">
<span id="tests"></span><h4>测试<a class="headerlink" href="#tests" title="永久链接至标题">¶</a></h4>
<ul class="simple">
<li>Added test <a class="reference internal" href="../topics/testing/tools.html#django.test.Client" title="django.test.Client"><code class="xref py py-class docutils literal notranslate"><span class="pre">Client</span></code></a> support for 307 and 308 redirects.</li>
<li>The test <a class="reference internal" href="../topics/testing/tools.html#django.test.Client" title="django.test.Client"><code class="xref py py-class docutils literal notranslate"><span class="pre">Client</span></code></a> now serializes a request data
dictionary as JSON if <code class="docutils literal notranslate"><span class="pre">content_type='application/json'</span></code>. You can customize
the JSON encoder with test client's <code class="docutils literal notranslate"><span class="pre">json_encoder</span></code> parameter.</li>
<li>The new <a class="reference internal" href="../topics/testing/tools.html#django.test.SimpleTestCase.assertWarnsMessage" title="django.test.SimpleTestCase.assertWarnsMessage"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SimpleTestCase.assertWarnsMessage()</span></code></a> method is a simpler
version of <a class="reference external" href="https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertWarnsRegex" title="(在 Python v3.10)"><code class="xref py py-meth docutils literal notranslate"><span class="pre">assertWarnsRegex()</span></code></a>.</li>
</ul>
</div>
</div>
</div>
<div class="section" id="s-backwards-incompatible-changes-in-2-1">
<span id="s-backwards-incompatible-2-1"></span><span id="backwards-incompatible-changes-in-2-1"></span><span id="backwards-incompatible-2-1"></span><h2>Backwards incompatible changes in 2.1<a class="headerlink" href="#backwards-incompatible-changes-in-2-1" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-database-backend-api">
<span id="database-backend-api"></span><h3>数据库后端 API<a class="headerlink" href="#database-backend-api" title="永久链接至标题">¶</a></h3>
<p>本节介绍了第三方数据库后端可能需要的更改。</p>
<ul class="simple">
<li>To adhere to <span class="target" id="index-1"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0249"><strong>PEP 249</strong></a>, exceptions where a database doesn't support a
feature are changed from <a class="reference external" href="https://docs.python.org/3/library/exceptions.html#NotImplementedError" title="(在 Python v3.10)"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> to
<a class="reference internal" href="../ref/exceptions.html#django.db.NotSupportedError" title="django.db.NotSupportedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">django.db.NotSupportedError</span></code></a>.</li>
<li>Renamed the <code class="docutils literal notranslate"><span class="pre">allow_sliced_subqueries</span></code> database feature flag to
<code class="docutils literal notranslate"><span class="pre">allow_sliced_subqueries_with_in</span></code>.</li>
<li><code class="docutils literal notranslate"><span class="pre">DatabaseOperations.distinct_sql()</span></code> now requires an additional <code class="docutils literal notranslate"><span class="pre">params</span></code>
argument and returns a tuple of SQL and parameters instead of an SQL string.</li>
<li><code class="docutils literal notranslate"><span class="pre">DatabaseFeatures.introspected_boolean_field_type</span></code> is changed from a method
to a property.</li>
</ul>
</div>
<div class="section" id="s-id1">
<span id="id1"></span><h3><a class="reference internal" href="../ref/contrib/gis/index.html#module-django.contrib.gis" title="django.contrib.gis: Geographic Information System (GIS) extensions for Django"><code class="xref py py-mod docutils literal notranslate"><span class="pre">django.contrib.gis</span></code></a><a class="headerlink" href="#id1" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li>Support for SpatiaLite 4.0 is removed.</li>
</ul>
</div>
<div class="section" id="s-dropped-support-for-mysql-5-5">
<span id="dropped-support-for-mysql-5-5"></span><h3>Dropped support for MySQL 5.5<a class="headerlink" href="#dropped-support-for-mysql-5-5" title="永久链接至标题">¶</a></h3>
<p>The end of upstream support for MySQL 5.5 is December 2018. Django 2.1 supports
MySQL 5.6 and higher.</p>
</div>
<div class="section" id="s-dropped-support-for-postgresql-9-3">
<span id="dropped-support-for-postgresql-9-3"></span><h3>Dropped support for PostgreSQL 9.3<a class="headerlink" href="#dropped-support-for-postgresql-9-3" title="永久链接至标题">¶</a></h3>
<p>The end of upstream support for PostgreSQL 9.3 is September 2018. Django 2.1
supports PostgreSQL 9.4 and higher.</p>
</div>
<div class="section" id="s-removed-bcryptpasswordhasher-from-the-default-password-hashers-setting">
<span id="removed-bcryptpasswordhasher-from-the-default-password-hashers-setting"></span><h3>Removed <code class="docutils literal notranslate"><span class="pre">BCryptPasswordHasher</span></code> from the default <code class="docutils literal notranslate"><span class="pre">PASSWORD_HASHERS</span></code> setting<a class="headerlink" href="#removed-bcryptpasswordhasher-from-the-default-password-hashers-setting" title="永久链接至标题">¶</a></h3>
<p>If you used bcrypt with Django 1.4 or 1.5 (before <code class="docutils literal notranslate"><span class="pre">BCryptSHA256PasswordHasher</span></code>
was added in Django 1.6), you might have some passwords that use the
<code class="docutils literal notranslate"><span class="pre">BCryptPasswordHasher</span></code> hasher.</p>
<p>You can check if that's the case like this:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">django.contrib.auth</span> <span class="kn">import</span> <span class="n">get_user_model</span>
<span class="n">User</span> <span class="o">=</span> <span class="n">get_user_model</span><span class="p">()</span>
<span class="n">User</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">password__startswith</span><span class="o">=</span><span class="s1">&#39;bcrypt$$&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>If you want to continue to allow those passwords to be used, you'll
have to define the <a class="reference internal" href="../ref/settings.html#std:setting-PASSWORD_HASHERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">PASSWORD_HASHERS</span></code></a> setting (if you don't already)
and include <code class="docutils literal notranslate"><span class="pre">'django.contrib.auth.hashers.BCryptPasswordHasher'</span></code>.</p>
</div>
<div class="section" id="s-moved-wrap-label-widget-template-context-variable">
<span id="moved-wrap-label-widget-template-context-variable"></span><h3>Moved <code class="docutils literal notranslate"><span class="pre">wrap_label</span></code> widget template context variable<a class="headerlink" href="#moved-wrap-label-widget-template-context-variable" title="永久链接至标题">¶</a></h3>
<p>To fix the lack of <code class="docutils literal notranslate"><span class="pre">&lt;label&gt;</span></code> when using <code class="docutils literal notranslate"><span class="pre">RadioSelect</span></code> and
<code class="docutils literal notranslate"><span class="pre">CheckboxSelectMultiple</span></code> with <code class="docutils literal notranslate"><span class="pre">MultiWidget</span></code>, the <code class="docutils literal notranslate"><span class="pre">wrap_label</span></code> context
variable now appears as an attribute of each option. For example, in a custom
<code class="docutils literal notranslate"><span class="pre">input_option.html</span></code> template, change <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">if</span> <span class="pre">wrap_label</span> <span class="pre">%}</span></code> to
<code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">if</span> <span class="pre">widget.wrap_label</span> <span class="pre">%}</span></code>.</p>
</div>
<div class="section" id="s-samesite-cookies">
<span id="samesite-cookies"></span><h3><code class="docutils literal notranslate"><span class="pre">SameSite</span></code> cookies<a class="headerlink" href="#samesite-cookies" title="永久链接至标题">¶</a></h3>
<p>The cookies used for <code class="docutils literal notranslate"><span class="pre">django.contrib.sessions</span></code>, <code class="docutils literal notranslate"><span class="pre">django.contrib.messages</span></code>,
and Django's CSRF protection now set the <code class="docutils literal notranslate"><span class="pre">SameSite</span></code> flag to <code class="docutils literal notranslate"><span class="pre">Lax</span></code> by
default. Browsers that respect this flag won't send these cookies on
cross-origin requests. If you rely on the old behavior, set the
<a class="reference internal" href="../ref/settings.html#std:setting-SESSION_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">SESSION_COOKIE_SAMESITE</span></code></a> and/or <a class="reference internal" href="../ref/settings.html#std:setting-CSRF_COOKIE_SAMESITE"><code class="xref std std-setting docutils literal notranslate"><span class="pre">CSRF_COOKIE_SAMESITE</span></code></a>
setting to <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
</div>
<div class="section" id="s-considerations-for-the-new-model-view-permission">
<span id="s-view-permission-backwards-incompatible"></span><span id="considerations-for-the-new-model-view-permission"></span><span id="view-permission-backwards-incompatible"></span><h3>Considerations for the new model &quot;view&quot; permission<a class="headerlink" href="#considerations-for-the-new-model-view-permission" title="永久链接至标题">¶</a></h3>
<div class="section" id="s-custom-admin-forms-need-to-take-the-view-only-case-into-account">
<span id="custom-admin-forms-need-to-take-the-view-only-case-into-account"></span><h4>Custom admin forms need to take the view-only case into account<a class="headerlink" href="#custom-admin-forms-need-to-take-the-view-only-case-into-account" title="永久链接至标题">¶</a></h4>
<p>With the new &quot;view&quot; permission, existing custom admin forms may raise errors
when a user doesn't have the change permission because the form might access
nonexistent fields. Fix this by overriding <a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.get_form" title="django.contrib.admin.ModelAdmin.get_form"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ModelAdmin.get_form()</span></code></a> and
checking if the user has the &quot;change&quot; permissions and returning the default
form if not:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">get_form</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_change_permission</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
            <span class="k">return</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get_form</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">obj</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">CustomForm</span>
</pre></div>
</div>
</div>
<div class="section" id="s-new-default-view-permission-could-allow-unwanted-access-to-admin-views">
<span id="new-default-view-permission-could-allow-unwanted-access-to-admin-views"></span><h4>New default view permission could allow unwanted access to admin views<a class="headerlink" href="#new-default-view-permission-could-allow-unwanted-access-to-admin-views" title="永久链接至标题">¶</a></h4>
<p>If you have a custom permission with a codename of the form
<code class="docutils literal notranslate"><span class="pre">view_&lt;modelname&gt;</span></code>, the new view permission handling in the admin will allow
view access to the changelist and detail pages for those models. If this is
unwanted, you must change your custom permission codename.</p>
</div>
</div>
<div class="section" id="s-miscellaneous">
<span id="miscellaneous"></span><h3>杂项<a class="headerlink" href="#miscellaneous" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li>The minimum supported version of <code class="docutils literal notranslate"><span class="pre">mysqlclient</span></code> is increased from 1.3.3 to
1.3.7.</li>
<li>Support for SQLite &lt; 3.7.15 is removed.</li>
<li>The date format of <code class="docutils literal notranslate"><span class="pre">Set-Cookie</span></code>'s <code class="docutils literal notranslate"><span class="pre">Expires</span></code> directive is changed to
follow <span class="target" id="index-2"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc7231.html#section-7.1.1.1"><strong>RFC 7231#section-7.1.1.1</strong></a> instead of Netscape's cookie standard.
Hyphens present in dates like <code class="docutils literal notranslate"><span class="pre">Tue,</span> <span class="pre">25-Dec-2018</span> <span class="pre">22:26:13</span> <span class="pre">GMT</span></code> are removed.
This change should be merely cosmetic except perhaps for antiquated browsers
that don't parse the new format.</li>
<li><code class="docutils literal notranslate"><span class="pre">allowed_hosts</span></code> is now a required argument of private API
<code class="docutils literal notranslate"><span class="pre">django.utils.http.is_safe_url()</span></code>.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">multiple</span></code> attribute rendered by the
<a class="reference internal" href="../ref/forms/widgets.html#django.forms.SelectMultiple" title="django.forms.SelectMultiple"><code class="xref py py-class docutils literal notranslate"><span class="pre">SelectMultiple</span></code></a> widget now uses HTML5 boolean syntax
rather than XHTML's <code class="docutils literal notranslate"><span class="pre">multiple=&quot;multiple&quot;</span></code>.</li>
<li>HTML rendered by form widgets no longer includes a closing slash on void
elements, e.g. <code class="docutils literal notranslate"><span class="pre">&lt;br&gt;</span></code>. This is incompatible within XHTML, although some
widgets already used aspects of HTML5 such as boolean attributes.</li>
<li>The value of <a class="reference internal" href="../ref/forms/widgets.html#django.forms.SelectDateWidget" title="django.forms.SelectDateWidget"><code class="xref py py-class docutils literal notranslate"><span class="pre">SelectDateWidget</span></code></a>'s empty options is
changed from 0 to an empty string, which mainly may require some adjustments
in tests that compare HTML.</li>
<li><a class="reference internal" href="../ref/contrib/auth.html#django.contrib.auth.models.User.has_usable_password" title="django.contrib.auth.models.User.has_usable_password"><code class="xref py py-meth docutils literal notranslate"><span class="pre">User.has_usable_password()</span></code></a> and the
<a class="reference internal" href="../topics/auth/passwords.html#django.contrib.auth.hashers.is_password_usable" title="django.contrib.auth.hashers.is_password_usable"><code class="xref py py-func docutils literal notranslate"><span class="pre">is_password_usable()</span></code></a> function no longer
return <code class="docutils literal notranslate"><span class="pre">False</span></code> if the password is <code class="docutils literal notranslate"><span class="pre">None</span></code> or an empty string, or if the
password uses a hasher that's not in the <a class="reference internal" href="../ref/settings.html#std:setting-PASSWORD_HASHERS"><code class="xref std std-setting docutils literal notranslate"><span class="pre">PASSWORD_HASHERS</span></code></a> setting.
This undocumented behavior was a regression in Django 1.6 and prevented users
with such passwords from requesting a password reset. Audit your code to
confirm that your usage of these APIs don't rely on the old behavior.</li>
<li>Since migrations are now loaded from <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files, you might need to delete
them if you're working in a mixed Python 2 and Python 3 environment.</li>
<li>Using <code class="docutils literal notranslate"><span class="pre">None</span></code> as a <a class="reference internal" href="../ref/contrib/postgres/fields.html#django.contrib.postgres.fields.JSONField" title="django.contrib.postgres.fields.JSONField"><code class="xref py py-class docutils literal notranslate"><span class="pre">JSONField</span></code></a> lookup
value now matches objects that have the specified key and a null value rather
than objects that don't have the key.</li>
<li>The admin CSS class <code class="docutils literal notranslate"><span class="pre">field-box</span></code> is renamed to <code class="docutils literal notranslate"><span class="pre">fieldBox</span></code> to prevent
conflicts with the class given to model fields named &quot;box&quot;.</li>
<li>Since the admin's <code class="docutils literal notranslate"><span class="pre">actions.html</span></code>, <code class="docutils literal notranslate"><span class="pre">change_list_results.html</span></code>,
<code class="docutils literal notranslate"><span class="pre">date_hierarchy.html</span></code>, <code class="docutils literal notranslate"><span class="pre">pagination.html</span></code>, <code class="docutils literal notranslate"><span class="pre">prepopulated_fields_js.html</span></code>,
<code class="docutils literal notranslate"><span class="pre">search_form.html</span></code>, and <code class="docutils literal notranslate"><span class="pre">submit_line.html</span></code> templates can now be
overridden per app or per model, you may need to rename existing templates
with those names that were written for a different purpose.</li>
<li><code class="docutils literal notranslate"><span class="pre">QuerySet.raw()</span></code> now caches its results like regular querysets. Use
<code class="docutils literal notranslate"><span class="pre">iterator()</span></code> if you don't want caching.</li>
<li>The database router <a class="reference internal" href="../topics/db/multi-db.html#allow_relation" title="allow_relation"><code class="xref py py-meth docutils literal notranslate"><span class="pre">allow_relation()</span></code></a> method is called in more cases.
Improperly written routers may need to be updated accordingly.</li>
<li>Translations are no longer deactivated before running management commands.
If your custom command requires translations to be deactivated (for example,
to insert untranslated content into the database), use the new
<a class="reference internal" href="../howto/custom-management-commands.html#management-commands-and-locales"><span class="std std-ref">&#64;no_translations decorator</span></a>.</li>
<li>Management commands no longer allow the abbreviated forms of the
<code class="docutils literal notranslate"><span class="pre">--settings</span></code> and <code class="docutils literal notranslate"><span class="pre">--pythonpath</span></code> arguments.</li>
<li>The private <code class="docutils literal notranslate"><span class="pre">django.db.models.sql.constants.QUERY_TERMS</span></code> constant is
removed. The <a class="reference internal" href="../ref/models/lookups.html#django.db.models.lookups.RegisterLookupMixin.get_lookup" title="django.db.models.lookups.RegisterLookupMixin.get_lookup"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_lookup()</span></code></a>
and <a class="reference internal" href="../ref/models/lookups.html#django.db.models.lookups.RegisterLookupMixin.get_lookups" title="django.db.models.lookups.RegisterLookupMixin.get_lookups"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_lookups()</span></code></a> methods
of the <a class="reference internal" href="../ref/models/lookups.html#lookup-registration-api"><span class="std std-ref">Lookup Registration API</span></a> may be
suitable alternatives. Compared to the <code class="docutils literal notranslate"><span class="pre">QUERY_TERMS</span></code> constant, they allow
your code to also account for any custom lookups that have been registered.</li>
<li>Compatibility with <code class="docutils literal notranslate"><span class="pre">py-bcrypt</span></code> is removed as it's unmaintained. Use <a class="reference external" href="https://pypi.org/project/bcrypt/">bcrypt</a> instead.</li>
</ul>
</div>
</div>
<div class="section" id="s-features-deprecated-in-2-1">
<span id="s-deprecated-features-2-1"></span><span id="features-deprecated-in-2-1"></span><span id="deprecated-features-2-1"></span><h2>在 2.1 中被废弃的功能<a class="headerlink" href="#features-deprecated-in-2-1" title="永久链接至标题">¶</a></h2>
<div class="section" id="s-id2">
<span id="id2"></span><h3>杂项<a class="headerlink" href="#id2" title="永久链接至标题">¶</a></h3>
<ul class="simple">
<li>The <code class="docutils literal notranslate"><span class="pre">ForceRHR</span></code> GIS function is deprecated in favor of the new
<a class="reference internal" href="../ref/contrib/gis/functions.html#django.contrib.gis.db.models.functions.ForcePolygonCW" title="django.contrib.gis.db.models.functions.ForcePolygonCW"><code class="xref py py-class docutils literal notranslate"><span class="pre">ForcePolygonCW</span></code></a> function.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils.http.cookie_date()</span></code> is deprecated in favor of
<a class="reference internal" href="../ref/utils.html#django.utils.http.http_date" title="django.utils.http.http_date"><code class="xref py py-func docutils literal notranslate"><span class="pre">http_date()</span></code></a>, which follows the format of the latest
RFC.</li>
<li><code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">staticfiles</span> <span class="pre">%}</span></code> and <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">admin_static</span> <span class="pre">%}</span></code> are deprecated
in favor of <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">static</span> <span class="pre">%}</span></code>, which works the same.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.contrib.staticfiles.templatetags.static()</span></code> is deprecated in favor
of <code class="docutils literal notranslate"><span class="pre">django.templatetags.static.static()</span></code>.</li>
<li>Support for <a class="reference internal" href="../ref/contrib/admin/index.html#django.contrib.admin.InlineModelAdmin.has_add_permission" title="django.contrib.admin.InlineModelAdmin.has_add_permission"><code class="xref py py-meth docutils literal notranslate"><span class="pre">InlineModelAdmin.has_add_permission()</span></code></a> methods that don't
accept <code class="docutils literal notranslate"><span class="pre">obj</span></code> as the second positional argument will be removed in Django
3.0.</li>
</ul>
</div>
</div>
<div class="section" id="s-features-removed-in-2-1">
<span id="s-removed-features-2-1"></span><span id="features-removed-in-2-1"></span><span id="removed-features-2-1"></span><h2>Features removed in 2.1<a class="headerlink" href="#features-removed-in-2-1" title="永久链接至标题">¶</a></h2>
<p>These features have reached the end of their deprecation cycle and are removed
in Django 2.1. See <a class="reference internal" href="1.11.html#deprecated-features-1-11"><span class="std std-ref">在 1.11 中被废弃的功能</span></a> for details, including how
to remove usage of these features.</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">contrib.auth.views.login()</span></code>, <code class="docutils literal notranslate"><span class="pre">logout()</span></code>, <code class="docutils literal notranslate"><span class="pre">password_change()</span></code>,
<code class="docutils literal notranslate"><span class="pre">password_change_done()</span></code>, <code class="docutils literal notranslate"><span class="pre">password_reset()</span></code>, <code class="docutils literal notranslate"><span class="pre">password_reset_done()</span></code>,
<code class="docutils literal notranslate"><span class="pre">password_reset_confirm()</span></code>, and <code class="docutils literal notranslate"><span class="pre">password_reset_complete()</span></code> are removed.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">extra_context</span></code> parameter of <code class="docutils literal notranslate"><span class="pre">contrib.auth.views.logout_then_login()</span></code>
is removed.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.test.runner.setup_databases()</span></code> is removed.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.utils.translation.string_concat()</span></code> is removed.</li>
<li><code class="docutils literal notranslate"><span class="pre">django.core.cache.backends.memcached.PyLibMCCache</span></code> no longer supports
passing <code class="docutils literal notranslate"><span class="pre">pylibmc</span></code> behavior settings as top-level attributes of <code class="docutils literal notranslate"><span class="pre">OPTIONS</span></code>.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">host</span></code> parameter of <code class="docutils literal notranslate"><span class="pre">django.utils.http.is_safe_url()</span></code> is removed.</li>
<li>Silencing of exceptions raised while rendering the <code class="docutils literal notranslate"><span class="pre">{%</span> <span class="pre">include</span> <span class="pre">%}</span></code> template
tag is removed.</li>
<li><code class="docutils literal notranslate"><span class="pre">DatabaseIntrospection.get_indexes()</span></code> is removed.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">authenticate()</span></code> method of authentication backends requires <code class="docutils literal notranslate"><span class="pre">request</span></code>
as the first positional argument.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">django.db.models.permalink()</span></code> decorator is removed.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">USE_ETAGS</span></code> setting is removed. <code class="docutils literal notranslate"><span class="pre">CommonMiddleware</span></code> and
<code class="docutils literal notranslate"><span class="pre">django.utils.cache.patch_response_headers()</span></code> no longer set ETags.</li>
<li>The <code class="docutils literal notranslate"><span class="pre">Model._meta.has_auto_field</span></code> attribute is removed.</li>
<li><code class="docutils literal notranslate"><span class="pre">url()</span></code>'s support for inline flags in regular expression groups (<code class="docutils literal notranslate"><span class="pre">(?i)</span></code>,
<code class="docutils literal notranslate"><span class="pre">(?L)</span></code>, <code class="docutils literal notranslate"><span class="pre">(?m)</span></code>, <code class="docutils literal notranslate"><span class="pre">(?s)</span></code>, and <code class="docutils literal notranslate"><span class="pre">(?u)</span></code>) is removed.</li>
<li>Support for <code class="docutils literal notranslate"><span class="pre">Widget.render()</span></code> methods without the <code class="docutils literal notranslate"><span class="pre">renderer</span></code> argument
is removed.</li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Django 2.1 版本发行说明</a><ul>
<li><a class="reference internal" href="#python-compatibility">Python 兼容性</a></li>
<li><a class="reference internal" href="#what-s-new-in-django-2-1">What's new in Django 2.1</a><ul>
<li><a class="reference internal" href="#model-view-permission">Model &quot;view&quot; permission</a></li>
<li><a class="reference internal" href="#minor-features">次要特性</a><ul>
<li><a class="reference internal" href="#django-contrib-admin"><code class="docutils literal notranslate"><span class="pre">django.contrib.admin</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-auth"><code class="docutils literal notranslate"><span class="pre">django.contrib.auth</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-gis"><code class="docutils literal notranslate"><span class="pre">django.contrib.gis</span></code></a></li>
<li><a class="reference internal" href="#django-contrib-sessions"><code class="docutils literal notranslate"><span class="pre">django.contrib.sessions</span></code></a></li>
<li><a class="reference internal" href="#cache">缓存</a></li>
<li><a class="reference internal" href="#csrf">CSRF</a></li>
<li><a class="reference internal" href="#forms">表单</a></li>
<li><a class="reference internal" href="#internationalization">国际化</a></li>
<li><a class="reference internal" href="#management-commands">管理命令</a></li>
<li><a class="reference internal" href="#migrations">迁移</a></li>
<li><a class="reference internal" href="#models">模型</a></li>
<li><a class="reference internal" href="#requests-and-responses">请求和响应</a></li>
<li><a class="reference internal" href="#templates">模板</a></li>
<li><a class="reference internal" href="#tests">测试</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#backwards-incompatible-changes-in-2-1">Backwards incompatible changes in 2.1</a><ul>
<li><a class="reference internal" href="#database-backend-api">数据库后端 API</a></li>
<li><a class="reference internal" href="#id1"><code class="docutils literal notranslate"><span class="pre">django.contrib.gis</span></code></a></li>
<li><a class="reference internal" href="#dropped-support-for-mysql-5-5">Dropped support for MySQL 5.5</a></li>
<li><a class="reference internal" href="#dropped-support-for-postgresql-9-3">Dropped support for PostgreSQL 9.3</a></li>
<li><a class="reference internal" href="#removed-bcryptpasswordhasher-from-the-default-password-hashers-setting">Removed <code class="docutils literal notranslate"><span class="pre">BCryptPasswordHasher</span></code> from the default <code class="docutils literal notranslate"><span class="pre">PASSWORD_HASHERS</span></code> setting</a></li>
<li><a class="reference internal" href="#moved-wrap-label-widget-template-context-variable">Moved <code class="docutils literal notranslate"><span class="pre">wrap_label</span></code> widget template context variable</a></li>
<li><a class="reference internal" href="#samesite-cookies"><code class="docutils literal notranslate"><span class="pre">SameSite</span></code> cookies</a></li>
<li><a class="reference internal" href="#considerations-for-the-new-model-view-permission">Considerations for the new model &quot;view&quot; permission</a><ul>
<li><a class="reference internal" href="#custom-admin-forms-need-to-take-the-view-only-case-into-account">Custom admin forms need to take the view-only case into account</a></li>
<li><a class="reference internal" href="#new-default-view-permission-could-allow-unwanted-access-to-admin-views">New default view permission could allow unwanted access to admin views</a></li>
</ul>
</li>
<li><a class="reference internal" href="#miscellaneous">杂项</a></li>
</ul>
</li>
<li><a class="reference internal" href="#features-deprecated-in-2-1">在 2.1 中被废弃的功能</a><ul>
<li><a class="reference internal" href="#id2">杂项</a></li>
</ul>
</li>
<li><a class="reference internal" href="#features-removed-in-2-1">Features removed in 2.1</a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="2.1.1.html"
                        title="上一章">Django 2.1.1 版本发行说明</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="2.0.13.html"
                        title="下一章">Django 2.0.13 版本发行说明</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/releases/2.1.txt"
            rel="nofollow">显示源代码</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>快速搜索</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="转向" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">12月 07, 2021</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="2.1.1.html" title="Django 2.1.1 版本发行说明">previous</a>
     |
    <a href="index.html" title="发行说明" accesskey="U">up</a>
   |
    <a href="2.0.13.html" title="Django 2.0.13 版本发行说明">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>